<?php 
require_once 'cntrlr/stocks.php';
?>
	<div class="products">
		<div id="pages">
			Резултати :
			<?php
				$n=getPagesNumber(count($array));
				for ($i=1;$i<=$n;$i++){
					if ($_GET['PN']==$i){
						echo "<font id='curr'>".$i."</font> ";
					} else
						echo $i." ";
				}
			?>
		</div>
		<table id="products">
			<?php
				foreach ($array as $obj) {
					echo "  <tr>
								<td width='120px' height ='120px'><img width='120px' height ='120px' src='images/products/".$obj->getImage()."' >
								</td>
								<td width='100px'>
									<a href='?page=search&searchField=".$obj->getProducer()."'>
										". $obj->getProducer() ."
									</a>
								</td>
								<td width='350px' id='description'>
									<a href='?page=stockInfo&name=".$obj->getName()."'>
										<h2 id='".$obj->getId()."'>".$obj->getName()."</h2><br/>
									".$obj->getShortDescription()."...
									</a>

								</td>
								<td width='80px' class='price'>
									<h2>";

					if ($obj->getPromoPrice() != null){
						printf("<del>%.2f лв </del>",$obj->getPrice() );
						printf("<br/> %.2f лв",$obj->getPromoPrice() );
					} else {
						printf("%.2f лв ",$obj->getPrice() );
					};
					echo       "</h2>
								</td>
								<td>
									Минимално количество <hr><br/> ".$obj->getMinimumQuantity()." ". $obj->getQuantity()."
								</td>
								<td id='buy'>
									<input type=\"text\" value=\"".$obj->getMinimumQuantity()."\" class=\"".$obj->getId()."\"style=\"width:25px;text-align: right;\">
									<br/><br/>
									<input  class='button' id='".$obj->getId()."' type='button' value=' Поръчай ''>
								</td>
							</tr>";
				}
			?>

		</table>
	</div>
<script>
	$('.button').click(function(){
		var id = $(this).attr("id");
		var  Quantity= $("."+id).val();
		var productName = $("h2#"+id).text();
		$.get("cntrlr/Cart.php", { quantity: Quantity, name: productName })
			.done(function(data) {
				$("#cart").hide(500,function(){
					$(this).html(data).show(500);

				});
			});

	});
</script>

